import { sys } from 'cc';

export class SyncStorage {
    static async getValue (key) {
      var ret = await Promise.resolve(sys.localStorage.getItem(key));
      return ret;
    }
  
    static async setValue (key, value) {
      return await sys.localStorage.setItem(key, value);
    }
    static async setStorageSync (key, value) {
      return await sys.localStorage.setItem(key, value);
    }
  
    static async removeKey (key) {
      await Promise.all(sys.localStorage.removeItem(key));
    }
  
    static async removeAllData () {
    
      const isFirst = await SyncStorage.getValue('is_first');
     
      let a = await Promise.all([
        sys.localStorage.clear(error => {
          // //////////////////console.error(error);
          // SyncStorage.setValue('is_agree', isAgrenn);
          SyncStorage.setValue('is_first', isFirst);
        }),
      ]);
      // await Promise.all(SyncStorage.setValue('is_agree', isAgrenn));
      await Promise.all(await SyncStorage.setValue('is_first', isFirst));
      return;
    }
  
    static async clearLoginData () {
      //清理登录数据
      await this.removeKey('token');
      await this.removeKey('phone');
      return;
    }
  }